#import sickbeard
#from sickbeard.providers.generic import GenericProvider
#set global $title="Config - Providers"
#set global $header="Search Providers"

#set global $sbPath="../.."

#set global $topmenu="config"#
#import os.path
#include $os.path.join($sickbeard.PROG_DIR, "data/interfaces/default/inc_top.tmpl")

<script type="text/javascript" src="$sbRoot/js/configProviders.js"></script>
<script type="text/javascript" src="$sbRoot/js/config.js"></script>
<script type="text/javascript" charset="utf-8">
<!--
\$(document).ready(function(){

var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#;
#for $curNewznabProvider in $sickbeard.newznabProviderList:
\$(this).addProvider('$curNewznabProvider.getID()', '$curNewznabProvider.name', '$curNewznabProvider.url', '$curNewznabProvider.key', $int($curNewznabProvider.default), show_nzb_providers);
#end for
});
//-->
</script>

<div id="config">
<div id="config-content">

<form id="configForm" action="saveProviders" method="post">

            <div id="config-components">
                
                <div id="core-component-group1" class="component-group clearfix">

                    <div class="component-group-desc">
                        <h3>Provider Priorities</h3>
                        <p>Check off and drag the providers into the order you want them to be used.</p>
                        <p class="note">At least one provider is required but two are recommended.</p>
                        <p>NZB/Torrent providers can be toggled in <a href="$sbRoot/config/search">Search Settings</a></p>
                        <p class="note"><span style="color: #654B24; font-size: 16px;">*</span> Provider does not support backlog searches at this time.</p>
                        <p class="note"><span style="color: #654B24; font-size: 16px;">**</span> Provider supports <b>limited</b> backlog searches, all episodes/qualities may not be available.</p>
                    </div>

                    <fieldset class="component-group-list">
                        <ul id="provider_order_list">
                        #for $curProvider in $sickbeard.providers.sortedProviderList():
                            #if $curProvider.providerType == $GenericProvider.NZB and not $sickbeard.USE_NZBS:
                                #continue
                            #elif $curProvider.providerType == $GenericProvider.TORRENT and not $sickbeard.USE_TORRENTS:
                                #continue
                            #end if
                            #set $curName = $curProvider.getID()
                          <li class="ui-state-default" id="$curName">
                            <input type="checkbox" id="enable_$curName" class="provider_enabler" #if $curProvider.isEnabled() then "checked=\"checked\"" else ""#/>
                            <a href="$curProvider.url" class="imgLink" target="_new"><img src="$sbRoot/images/providers/$curProvider.imageName()" alt="$curProvider.name" title="$curProvider.name" width="16" height="16" /></a>
                            $curProvider.name
                            #if not $curProvider.supportsBacklog then "*" else ""#
                            #if $curProvider.name == "EZRSS" then "**" else ""#
                          </li>
                        #end for
                        </ul>
                        <input type="hidden" name="provider_order" id="provider_order" value="<%=" ".join([x.getID()+':'+str(int(x.isEnabled())) for x in sickbeard.providers.sortedProviderList()])%>"/>
                        <br/><input type="submit" class="config_submitter" value="Save Changes" /><br/>
                    </fieldset>
                </div><!-- /component-group1 //-->

                <div id="core-component-group2" class="component-group clearfix">

                    <div class="component-group-desc">
                        <h3>Configure Built-In<br />Providers</h3>
                        <p>Check with provider's website on how to obtain an API key if needed.</p>
                    </div>
                    
                    <fieldset class="component-group-list">
                        <div class="field-pair">
                            <label class="clearfix" for="editAProvider">
                                <span class="component-title jumbo">Configure Provider:</span>
                                <span class="component-desc">
                                    #set $provider_config_list = []
                                    #for $cur_provider in ("nzbs_org", "nzbs_r_us", "newzbin", "nzbmatrix", "tvtorrents", "binsearch"):
                                        #set $cur_provider_obj = $sickbeard.providers.getProviderClass($cur_provider)
                                        #if $cur_provider_obj.providerType == $GenericProvider.NZB and not $sickbeard.USE_NZBS:
                                            #continue
                                        #elif $cur_provider_obj.providerType == $GenericProvider.TORRENT and not $sickbeard.USE_TORRENTS:
                                            #continue
                                        #end if
                                        $provider_config_list.append($cur_provider_obj)
                                    #end for

                                    #if $provider_config_list:                                        
                                    <select id="editAProvider">
                                        #for $cur_provider in $provider_config_list + [$curProvider for $curProvider in $sickbeard.newznabProviderList if $curProvider.default and $curProvider.needs_auth]:
                                            <option value="$cur_provider.getID()">$cur_provider.name</option>
                                        #end for
                                    </select>
                                    #else:
                                    No providers available to configure.
                                    #end if
                                </span>
                            </label>
                        </div>


<!-- start div for editing providers //-->
#for $curNewznabProvider in [$curProvider for $curProvider in $sickbeard.newznabProviderList if $curProvider.default and $curProvider.needs_auth]:
<div class="providerDiv" id="${curNewznabProvider.getID()}Div">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">$curNewznabProvider.name URL</span>
                                <input class="component-desc" type="text" id="${curNewznabProvider.getID()}_url" value="$curNewznabProvider.url" size="40" disabled/>
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">$curNewznabProvider.name API Key</span>
                                <input class="component-desc newznab_key" type="text" id="${curNewznabProvider.getID()}_hash" value="$curNewznabProvider.key" size="40" />
                            </label>
                        </div>
</div>
#end for


<div class="providerDiv" id="nzbs_orgDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBs.org UID</span>
                                <input class="component-desc" type="text" name="nzbs_org_uid" value="$sickbeard.NZBS_UID" size="10" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBs.org Hash</span>
                                <input class="component-desc" type="text" name="nzbs_org_hash" value="$sickbeard.NZBS_HASH" size="40" />
                            </label>
                        </div>
</div>

<div class="providerDiv" id="nzbmatrixDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBMatrix Username</span>
                                <input class="component-desc" type="text" name="nzbmatrix_username" value="$sickbeard.NZBMATRIX_USERNAME" size="10" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBMatrix API Key</span>
                                <input class="component-desc" type="text" name="nzbmatrix_apikey" value="$sickbeard.NZBMATRIX_APIKEY" size="40" />
                            </label>
                        </div>
</div>

<div class="providerDiv" id="newzbinDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">Newzbin Username</span>
                                <input class="component-desc" type="text" name="newzbin_username" value="$sickbeard.NEWZBIN_USERNAME" size="10" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">Newzbin Password</span>
                                <input class="component-desc" type="password" name="newzbin_password" value="$sickbeard.NEWZBIN_PASSWORD" size="40" />
                            </label>
                        </div>
</div>

<div class="providerDiv" id="nzbs_r_usDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBs'R'US UID</span>
                                <input class="component-desc" type="text" name="nzbs_r_us_uid" value="$sickbeard.NZBSRUS_UID" size="10" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">NZBs'R'US Hash</span>
                                <input class="component-desc" type="text" name="nzbs_r_us_hash" value="$sickbeard.NZBSRUS_HASH" size="40" />
                            </label>
                        </div>
</div>

<div class="providerDiv" id="binsearchDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">BinSearch Max results by call value</span>
                                <input class="component-desc" type="text" name="binsearch_max" value="$sickbeard.BINSEARCH_MAX" size="4" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">BinSearch group to collect</span>
                                <input class="component-desc" type="text" name="binsearch_alt" value="$sickbeard.BINSEARCH_ALT" size="60" />
                            </label>
                        </div>
</div>

<div class="providerDiv" id="tvtorrentsDiv">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">TvTorrents Digest:</span>
                                <input class="component-desc" type="text" name="tvtorrents_digest" value="$sickbeard.TVTORRENTS_DIGEST" size="40" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title">TvTorrents Hash:</span>
                                <input class="component-desc" type="text" name="tvtorrents_hash" value="$sickbeard.TVTORRENTS_HASH" size="40" />
                            </label>
                        </div>
</div>

<!-- end div for editing providers -->

                    <input type="submit" class="config_submitter" value="Save Changes" /><br/>
            
                    </fieldset>
                </div><!-- /component-group2 //-->

                <div id="core-component-group3" class="component-group clearfix">

                    <div class="component-group-desc">
                        <h3>Configure Custom<br />Newznab Providers</h3>
                        <p>Add and setup custom Newznab providers.</p>
                        <p>Some built-in Newznab providers are already available above.</p>
                    </div>

                    <fieldset class="component-group-list">
                        <div class="field-pair">
                            <label class="clearfix">
                                <span class="component-title jumbo">Select Provider:</span>
                                <span class="component-desc">
                                    <input type="hidden" name="newznab_string" id="newznab_string" />
                                    <select id="editANewznabProvider">
                                        <option value="addNewznab">-- add new provider --</option>
                                    </select>
                                </span>
                            </label>
                        </div>

<div class="newznabProviderDiv" id="addNewznab">
                        <div class="field-pair">
                            <label class="nocheck clearfix">
                                <span class="component-title">Provider Name</span>
                                <input class="component-desc" type="text" id="newznab_name" size="40" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="nocheck clearfix">
                                <span class="component-title">Site URL</span>
                                <input class="component-desc" type="text" id="newznab_url" size="40" />
                            </label>
                        </div>
                        <div class="field-pair">
                            <label class="nocheck clearfix">
                                <span class="component-title">API Key</span>
                                <input class="component-desc" type="text" id="newznab_key" size="40" />
                            </label>
                            <label class="nocheck clearfix">
                                <span class="component-title">&nbsp;</span>
                                <span class="component-desc">(leave blank if not required)</span>
                            </label>
                        </div>
            <div id="newznab_add_div">
                <input type="button" class="newznab_save" id="newznab_add" value="Add" />
            </div>
            <div id="newznab_update_div" style="display: none;">
                <input type="button" class="newznab_delete" id="newznab_delete" value="Delete" />
            </div> 
</div>

                    </fieldset>
                </div><!-- /component-group3 //-->

                    
            <br/><input type="submit" class="config_submitter" value="Save Changes" /><br/>
                
            </div><!-- /config-components //-->

</form>
</div></div>
<div class="clearfix"></div>

#include $os.path.join($sickbeard.PROG_DIR, "data/interfaces/default/inc_bottom.tmpl")
